import java.util.Scanner;

/**
 * @Title: 模拟队列
 * @Author 贾金博
 * @Package PACKAGE_NAME
 * @Date 2024/3/2 20:28
 * @description:
 */
public class 模拟队列 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n + 10];
        int low = 0, up = -1;

        for (int i = 0; i < n; i++) {
            String s = sc.next();
            if("push".equals(s)) { // 插入
                int x = sc.nextInt();
                up = (up + 1) % (n + 10);
                a[up] = x;
            } else if("pop".equals(s)) {
                low ++ ;
            } else if("empty".equals(s)) {
                System.out.println(low == up + 1 ? "YES" : "NO");
            } else { // 查询队头元素
                System.out.println(a[low]);
            }
        }
    }
}
